


use  "$path_data/data/temp/main_reg_data_psc.dta", replace


gen dummy_age_missing = 1 if age==.
recode dummy_age_missing(.=0)
gen age_nonmis = age if dummy_age_missing == 0
replace age_nonmis = 0 if dummy_age_missing == 1
gen age_sq_nonmis = age_sq if dummy_age_missing == 0
replace age_sq_nonmis = 0 if dummy_age_missing == 1






forvalues i =1/8 {
	foreach s in be se pv rpv wpv {
		matrix psc`i'_math_`s' = J(7,1,.)
	}
}



foreach s in be se pv rpv wpv {
	matrix est_ols_nocont_`s' = J(7,1,.)
}
foreach s in be se pv rpv wpv {
	matrix est_ols_gender_`s' = J(7,1,.)
}
foreach s in be se pv rpv wpv {
	matrix est_ols_age_`s' = J(7,1,.)
}

foreach s in be se pv rpv wpv {
	matrix est_lee_bounds_nocont_`s' = J(7,1,.)
}

foreach s in be se pv rpv wpv {
	matrix est_lee_bounds_gender_`s' = J(7,1,.)
}




reg dif_psc treatment if ptsbl_overall_score != ., cluster(school_no)


	matrix est_ols_nocont_temp = r(table)
	matrix est_ols_nocont_r2 = e(r2)
	matrix est_ols_nocont_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_ols_nocont_be[`j',1] = est_ols_nocont_temp[1,`j']
		* standard error
		matrix est_ols_nocont_se[`j',1] = est_ols_nocont_temp[2,`j']
		* p value
		matrix est_ols_nocont_pv[`j',1] = est_ols_nocont_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


reg dif_psc treatment student_gender if ptsbl_overall_score != ., cluster(school_no)


	matrix est_ols_gender_temp = r(table)
	matrix est_ols_gender_r2 = e(r2)
	matrix est_ols_gender_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_ols_gender_be[`j',1] = est_ols_gender_temp[1,`j']
		* standard error
		matrix est_ols_gender_se[`j',1] = est_ols_gender_temp[2,`j']
		* p value
		matrix est_ols_gender_pv[`j',1] = est_ols_gender_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


reg dif_psc treatment student_gender age_nonmis age_sq_nonmis dummy_age_missing if ptsbl_overall_score != ., cluster(school_no)


	matrix est_ols_age_temp = r(table)
	matrix est_ols_age_r2 = e(r2)
	matrix est_ols_age_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_ols_age_be[`j',1] = est_ols_age_temp[1,`j']
		* standard error
		matrix est_ols_age_se[`j',1] = est_ols_age_temp[2,`j']
		* p value
		matrix est_ols_age_pv[`j',1] = est_ols_age_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)










teffects psmatch (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis , probit)  if ptsbl_overall_score != .,atet


	matrix psc2_math_temp = r(table)
	matrix psc2_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc2_math_be[`j',1] = psc2_math_temp[1,`j']
		* standard error
		matrix psc2_math_se[`j',1] = psc2_math_temp[2,`j']
		* p value
		matrix psc2_math_pv[`j',1] = psc2_math_temp[4,`j']
	}




teffects psmatch (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit)  if ptsbl_overall_score != .,ate


	matrix psc3_math_temp = r(table)
	matrix psc3_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc3_math_be[`j',1] = psc3_math_temp[1,`j']
		* standard error
		matrix psc3_math_se[`j',1] = psc3_math_temp[2,`j']
		* p value
		matrix psc3_math_pv[`j',1] = psc3_math_temp[4,`j']
	}




teffects ipw (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit) if ptsbl_overall_score != ., atet


	matrix psc4_math_temp = r(table)
	matrix psc4_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc4_math_be[`j',1] = psc4_math_temp[1,`j']
		* standard error
		matrix psc4_math_se[`j',1] = psc4_math_temp[2,`j']
		* p value
		matrix psc4_math_pv[`j',1] = psc4_math_temp[4,`j']
	}


teffects ipw (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit) if ptsbl_overall_score != ., ate


	matrix psc5_math_temp = r(table)
	matrix psc5_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc5_math_be[`j',1] = psc5_math_temp[1,`j']
		* standard error
		matrix psc5_math_se[`j',1] = psc5_math_temp[2,`j']
		* p value
		matrix psc5_math_pv[`j',1] = psc5_math_temp[4,`j']
	}

	
	

	
leebounds dif_psc treatment if ptsbl_overall_score != ., vce(bootstrap, reps(4999)) 

mat est_lee_bounds_nocont = r(table)
mat obs_lee_bounds_nocont = e(N)
mat obs_sl_lee_bounds_nocont = e(Nsel)


	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_lee_bounds_nocont_be[`j',1] = est_lee_bounds_nocont[1,`j']
		* standard error
		matrix est_lee_bounds_nocont_se[`j',1] = est_lee_bounds_nocont[2,`j']
		* p value
		matrix est_lee_bounds_nocont_pv[`j',1] = est_lee_bounds_nocont[4,`j']
	}

	

leebounds dif_psc treatment if ptsbl_overall_score != .,  tight(student_gender) vce(bootstrap, reps(4999)) 

mat est_lee_bounds_gender = r(table)
mat obs_lee_bounds_gender = e(N)
mat obs_sl_lee_bounds_gender = e(Nsel)


	
		foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_lee_bounds_gender_be[`j',1] = est_lee_bounds_gender[1,`j']
		* standard error
		matrix est_lee_bounds_gender_se[`j',1] = est_lee_bounds_gender[2,`j']
		* p value
		matrix est_lee_bounds_gender_pv[`j',1] = est_lee_bounds_gender[4,`j']
	}

	
	
	
	
	
	
	
	
	
	
	
	

	
	
	

foreach p in math  {
forvalues item = 1/2 {
		forvalues scale = 2/5 {
		if psc`scale'_`p'_pv[`item',1]<=0.01 {
			local star_`p'_`item'`scale' %3s "***"
		}
		else if (psc`scale'_`p'_pv[`item', 1]>0.01) & (psc`scale'_`p'_pv[`item', 1]<=0.05) {
			local star_`p'_`item'`scale' %2s "**"
		}
		else if (psc`scale'_`p'_pv[`item', 1]>0.05) & (psc`scale'_`p'_pv[`item', 1]<=0.10) {
			local star_`p'_`item'`scale' %1s "*"
		}
		else {
			local star_`p'_`item'`scale'  ""
		}
	} // forvalues `scale' loop

}  // forvalues `item' loop
}  // foreach `p' loop









*foreach p in ols_nocont ols_gender ols_age lee_bounds_nocont lee_bounds_gender lee_bounds_nocont5 lee_bounds_gender5 {
foreach p in ols_nocont ols_gender ols_age lee_bounds_nocont lee_bounds_gender {
forvalues item = 1/2 {
*		forvalues scale = 1/6 {
		if est_`p'_pv[`item',1]<=0.01 {
			local star_`p'_`item' %3s "***"
		}
		else if (est_`p'_pv[`item',1]>0.01) & (est_`p'_pv[`item',1]<=0.05) {
			local star_`p'_`item' %2s "**"
		}
		else if (est_`p'_pv[`item',1]>0.05) & (est_`p'_pv[`item',1]<=0.10) {
			local star_`p'_`item' %1s "*"
		}
		else {
			local star_`p'_`item'  ""
		}
*	} // forvalues `scale' loop

}  // forvalues `item' loop
}  // foreach `p' loop





	

tempname hh
file open `hh' using "$pardir/table5.tex", write replace
file write `hh' "" _newline
file write `hh' "% Date: `c(current_date)'" _newline
file write `hh' "% Time: `c(current_time)'" _newline
file write `hh' "" _newline







file write `hh' "\begin{table}[t!]" _newline
file write `hh' "\centering" _newline
file write `hh' "\caption{Long-term Impact of Kumon on Students’ Learning Outcomes: Result of Lee bounds}" _newline
file write `hh' "\label{tab:PSC_math}" _newline
file write `hh' "\scalebox{0.58}{" _newline
file write `hh' "\begin{threeparttable}" _newline
file write `hh' "\begin{tabular}{lccccc}\toprule" _newline 

file write `hh' " &&&&& \\" _newline




file write `hh' "\multicolumn{6}{l}{\textbf{Panel B: PSC Score}} \\\midrule" _newline
file write `hh' " &&&&& \\" _newline
file write `hh' "\multicolumn{6}{l}{\textbf{Panel B1: OLS Results}} \\\midrule" _newline
file write `hh' "Dependent Variable & \multicolumn{5}{c} {First Difference of PSC Math Score and Baseline PTSII-C Score} \\"_newline
file write `hh' "\cmidrule{2-6}"_newline

*file write `hh' "    &        \multicolumn{1}{c}{Lower Bound Estimate}  &    \multicolumn{1}{c}{Upper Bound Estimate}  && &   \\" _newline
file write `hh' "                                                                   & (1)  &    (2)  && (3) &   \\\midrule" _newline
file write `hh' "Treatment     &  " %04.3f (est_ols_nocont_be[1,1]) `star_est_ols_nocont_1' "   &  " %04.3f (est_ols_gender_be[1,1]) `star_est_ols_gender_1' "     &&  " %04.3f (est_ols_age_be[1,1]) `star_est_ols_age_1' "    &  " "        \\" _newline
file write `hh' "              &  (" %04.3f (est_ols_nocont_se[1,1])                 ")  & ("  %04.3f (est_ols_gender_se[1,1])                  ")  &&  (" %04.3f (est_ols_age_se[1,1])                  ")  &   \\" _newline


file write `hh' "Controlling for Gender & 				& x 		&&		x & 	\\" _newline
file write `hh' "Controlling for Age, and Age Squared & 				&  		&&	x	 & 	\\" _newline
file write `hh' "              & & && &  \\" _newline

file write `hh' "Num of Obs.   &   "        (est_ols_nocont_obs[1,1])                "   &  "        (est_ols_gender_obs[1,1])                 "  &&  "        (est_ols_age_obs[1,1])                 "   &     \\\midrule" _newline

file write `hh' " &&&&& \\" _newline







file write `hh' "\multicolumn{6}{l}{\textbf{Panel B2: Point Estimation with Selection}} \\\midrule" _newline
file write `hh' "                                                             & \multicolumn{2}{c}{PSM regression}                                    && \multicolumn{2}{c}{IPW regression}    \\" _newline
file write `hh' "   \cmidrule{2-3} \cmidrule{5-6}  &         ATT estimates    &     ATE estimates     &&      ATT estimates    &     ATE estimates   \\" _newline
file write `hh' "                                                                   & (1)  &    (2)  && (3)  & (4)  \\\midrule" _newline
file write `hh' "Treatment     &  " %04.3f (psc2_math_be[1,1]) `star_math_12' "   &  " %04.3f (psc3_math_be[1,1]) `star_math_13' "     && " %04.3f (psc4_math_be[1,1]) `star_math_14' "     &  " %04.3f (psc5_math_be[1,1]) `star_math_15' "        \\" _newline
file write `hh' "              &  (" %04.3f (psc2_math_se[1,1])                 ")  & (" %04.3f (psc3_math_se[1,1])                  ")  &&  (" %04.3f (psc4_math_se[1,1])                  ")  & (" %04.3f (psc5_math_se[1,1])                  ")   \\" _newline
file write `hh' "Constant      &       &      &&  " %04.3f (psc4_math_be[2,1]) `star_math_24' "     &  " %04.3f (psc5_math_be[2,1]) `star_math_25' "     \\" _newline
file write `hh' "              &    &   && (" %04.3f (psc4_math_se[2,1])                  ")  & (" %04.3f (psc5_math_se[2,1])                  ")    \\" _newline
file write `hh' "              & & && &  \\" _newline
file write `hh' "Num of Obs.   &   "        (psc2_math_obs[1,1])                "   &  "        (psc3_math_obs[1,1])                 "  &&  "        (psc4_math_obs[1,1])                 "   &  "        (psc5_math_obs[1,1])                 "     \\\midrule" _newline






file write `hh' "\multicolumn{6}{l}{\textbf{Panel B3: Lee's Bounds}} \\\midrule" _newline

file write `hh' "    &        \multicolumn{2}{c}{Lower Bound Estimate}  &&     \multicolumn{2}{c}{Upper Bound Estimate}    \\" _newline
file write `hh' "                                                                   & (1)  &    (2)  && (3)  & (4)  \\\midrule" _newline
file write `hh' "Treatment     &  " %04.3f (est_lee_bounds_nocont_be[1,1]) `star_lee_bounds_nocont_1' "   &  " %04.3f (est_lee_bounds_gender_be[1,1]) `star_lee_bounds_gender_1' "     && " %04.3f (est_lee_bounds_nocont_be[2,1]) `star_lee_bounds_nocont_2' "   &  " %04.3f (est_lee_bounds_gender_be[2,1]) `star_lee_bounds_gender_2' "        \\" _newline
file write `hh' "              &  (" %04.3f (est_lee_bounds_nocont_se[1,1])                 ")  & (" %04.3f (est_lee_bounds_gender_se[1,1])                  ")  &&  (" %04.3f (est_lee_bounds_nocont_se[2,1])                  ")  & (" %04.3f (est_lee_bounds_gender_se[2,1])                  ")   \\" _newline

file write `hh' "Control in Selection Equation (Gender) & 				& x 		&&		 & x	\\" _newline

file write `hh' "              & & && &  \\" _newline

file write `hh' "Num of Selected Obs.\textsuperscript{a}   &   "        (obs_sl_lee_bounds_nocont[1,1])                "   &  "        (obs_sl_lee_bounds_gender[1,1])                 "  &&  "        (obs_sl_lee_bounds_nocont[1,1])                  "   &  "         (obs_sl_lee_bounds_gender[1,1])                 "     \\" _newline

file write `hh' "Num of Total Obs.\textsuperscript{b}   &   "        (obs_lee_bounds_nocont[1,1])                "   &  "        (obs_lee_bounds_gender[1,1])                 "  &&  "        (obs_lee_bounds_nocont[1,1])                  "   &  "         (obs_lee_bounds_gender[1,1])                 "     \\\bottomrule" _newline




file write `hh' "\end{tabular}" _newline
file write `hh' "\end{threeparttable}" _newline
file write `hh' "}" _newline
file write `hh' "\label{tab:addlabelaaa}%" _newline
file write `hh' "\end{table}" _newline







file write `hh' "" _newline
file write `hh' "" _newline
file write `hh' "" _newline
file write `hh' "" _newline

file close `hh'


	
	
	
	
	
	
	
preserve
	
keep if grade == 4







forvalues i =1/8 {
	foreach s in be se pv rpv wpv {
		matrix psc`i'_math_`s' = J(7,1,.)
	}
}



foreach s in be se pv rpv wpv {
	matrix est_ols_nocont_`s' = J(7,1,.)
}
foreach s in be se pv rpv wpv {
	matrix est_ols_gender_`s' = J(7,1,.)
}
foreach s in be se pv rpv wpv {
	matrix est_ols_age_`s' = J(7,1,.)
}

foreach s in be se pv rpv wpv {
	matrix est_lee_bounds_nocont_`s' = J(7,1,.)
}

foreach s in be se pv rpv wpv {
	matrix est_lee_bounds_gender_`s' = J(7,1,.)
}




reg dif_psc treatment if ptsbl_overall_score != ., cluster(school_no)


	matrix est_ols_nocont_temp = r(table)
	matrix est_ols_nocont_r2 = e(r2)
	matrix est_ols_nocont_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_ols_nocont_be[`j',1] = est_ols_nocont_temp[1,`j']
		* standard error
		matrix est_ols_nocont_se[`j',1] = est_ols_nocont_temp[2,`j']
		* p value
		matrix est_ols_nocont_pv[`j',1] = est_ols_nocont_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


reg dif_psc treatment student_gender if ptsbl_overall_score != ., cluster(school_no)


	matrix est_ols_gender_temp = r(table)
	matrix est_ols_gender_r2 = e(r2)
	matrix est_ols_gender_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_ols_gender_be[`j',1] = est_ols_gender_temp[1,`j']
		* standard error
		matrix est_ols_gender_se[`j',1] = est_ols_gender_temp[2,`j']
		* p value
		matrix est_ols_gender_pv[`j',1] = est_ols_gender_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


reg dif_psc treatment student_gender age_nonmis age_sq_nonmis dummy_age_missing if ptsbl_overall_score != ., cluster(school_no)


	matrix est_ols_age_temp = r(table)
	matrix est_ols_age_r2 = e(r2)
	matrix est_ols_age_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_ols_age_be[`j',1] = est_ols_age_temp[1,`j']
		* standard error
		matrix est_ols_age_se[`j',1] = est_ols_age_temp[2,`j']
		* p value
		matrix est_ols_age_pv[`j',1] = est_ols_age_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)










teffects psmatch (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis , probit)  if ptsbl_overall_score != .,atet


	matrix psc2_math_temp = r(table)
	matrix psc2_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc2_math_be[`j',1] = psc2_math_temp[1,`j']
		* standard error
		matrix psc2_math_se[`j',1] = psc2_math_temp[2,`j']
		* p value
		matrix psc2_math_pv[`j',1] = psc2_math_temp[4,`j']
	}




teffects psmatch (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit)  if ptsbl_overall_score != .,ate


	matrix psc3_math_temp = r(table)
	matrix psc3_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc3_math_be[`j',1] = psc3_math_temp[1,`j']
		* standard error
		matrix psc3_math_se[`j',1] = psc3_math_temp[2,`j']
		* p value
		matrix psc3_math_pv[`j',1] = psc3_math_temp[4,`j']
	}




teffects ipw (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit) if ptsbl_overall_score != ., atet


	matrix psc4_math_temp = r(table)
	matrix psc4_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc4_math_be[`j',1] = psc4_math_temp[1,`j']
		* standard error
		matrix psc4_math_se[`j',1] = psc4_math_temp[2,`j']
		* p value
		matrix psc4_math_pv[`j',1] = psc4_math_temp[4,`j']
	}


teffects ipw (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit) if ptsbl_overall_score != ., ate


	matrix psc5_math_temp = r(table)
	matrix psc5_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc5_math_be[`j',1] = psc5_math_temp[1,`j']
		* standard error
		matrix psc5_math_se[`j',1] = psc5_math_temp[2,`j']
		* p value
		matrix psc5_math_pv[`j',1] = psc5_math_temp[4,`j']
	}

	
	


	
	
leebounds dif_psc treatment if ptsbl_overall_score != ., vce(bootstrap, reps(4999)) 

mat est_lee_bounds_nocont = r(table)
mat obs_lee_bounds_nocont = e(N)
mat obs_sl_lee_bounds_nocont = e(Nsel)


	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_lee_bounds_nocont_be[`j',1] = est_lee_bounds_nocont[1,`j']
		* standard error
		matrix est_lee_bounds_nocont_se[`j',1] = est_lee_bounds_nocont[2,`j']
		* p value
		matrix est_lee_bounds_nocont_pv[`j',1] = est_lee_bounds_nocont[4,`j']
	}

	

leebounds dif_psc treatment if ptsbl_overall_score != .,  tight(student_gender) vce(bootstrap, reps(4999)) 

mat est_lee_bounds_gender = r(table)
mat obs_lee_bounds_gender = e(N)
mat obs_sl_lee_bounds_gender = e(Nsel)


	
		foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_lee_bounds_gender_be[`j',1] = est_lee_bounds_gender[1,`j']
		* standard error
		matrix est_lee_bounds_gender_se[`j',1] = est_lee_bounds_gender[2,`j']
		* p value
		matrix est_lee_bounds_gender_pv[`j',1] = est_lee_bounds_gender[4,`j']
	}

	
	
	
	
	
	
	
	
	
	
	
	

	
	
	

foreach p in math  {
forvalues item = 1/2 {
		forvalues scale = 2/5 {
		if psc`scale'_`p'_pv[`item',1]<=0.01 {
			local star_`p'_`item'`scale' %3s "***"
		}
		else if (psc`scale'_`p'_pv[`item', 1]>0.01) & (psc`scale'_`p'_pv[`item', 1]<=0.05) {
			local star_`p'_`item'`scale' %2s "**"
		}
		else if (psc`scale'_`p'_pv[`item', 1]>0.05) & (psc`scale'_`p'_pv[`item', 1]<=0.10) {
			local star_`p'_`item'`scale' %1s "*"
		}
		else {
			local star_`p'_`item'`scale'  ""
		}
	} // forvalues `scale' loop

}  // forvalues `item' loop
}  // foreach `p' loop






*foreach p in ols_nocont ols_gender ols_age lee_bounds_nocont lee_bounds_gender lee_bounds_nocont5 lee_bounds_gender5 {
foreach p in ols_nocont ols_gender ols_age lee_bounds_nocont lee_bounds_gender {
forvalues item = 1/2 {
*		forvalues scale = 1/6 {
		if est_`p'_pv[`item',1]<=0.01 {
			local star_`p'_`item' %3s "***"
		}
		else if (est_`p'_pv[`item',1]>0.01) & (est_`p'_pv[`item',1]<=0.05) {
			local star_`p'_`item' %2s "**"
		}
		else if (est_`p'_pv[`item',1]>0.05) & (est_`p'_pv[`item',1]<=0.10) {
			local star_`p'_`item' %1s "*"
		}
		else {
			local star_`p'_`item'  ""
		}
*	} // forvalues `scale' loop

}  // forvalues `item' loop
}  // foreach `p' loop




	

tempname hh
file open `hh' using "$pardir/tableH2_panelB.tex", write replace
file write `hh' "" _newline
file write `hh' "% Date: `c(current_date)'" _newline
file write `hh' "% Time: `c(current_time)'" _newline
file write `hh' "" _newline







file write `hh' "\begin{table}[t!]" _newline
file write `hh' "\centering" _newline
file write `hh' "\caption{Long-term Impact of Kumon on Students’ Learning Outcomes: Result of Lee bounds}" _newline
file write `hh' "\label{tab:PSC_math}" _newline
file write `hh' "\scalebox{0.58}{" _newline
file write `hh' "\begin{threeparttable}" _newline
file write `hh' "\begin{tabular}{lccccc}\toprule" _newline 

file write `hh' " &&&&& \\" _newline




file write `hh' "\multicolumn{6}{l}{\textbf{Panel B: PSC Score}} \\\midrule" _newline
file write `hh' " &&&&& \\" _newline
file write `hh' "\multicolumn{6}{l}{\textbf{Panel B1: OLS Results}} \\\midrule" _newline
file write `hh' "Dependent Variable & \multicolumn{5}{c} {First Difference of PSC Math Score and Baseline PTSII-C Score} \\"_newline
file write `hh' "\cmidrule{2-6}"_newline

*file write `hh' "    &        \multicolumn{1}{c}{Lower Bound Estimate}  &    \multicolumn{1}{c}{Upper Bound Estimate}  && &   \\" _newline
file write `hh' "                                                                   & (1)  &    (2)  && (3) &   \\\midrule" _newline
file write `hh' "Treatment     &  " %04.3f (est_ols_nocont_be[1,1]) `star_est_ols_nocont_1' "   &  " %04.3f (est_ols_gender_be[1,1]) `star_est_ols_gender_1' "     &&  " %04.3f (est_ols_age_be[1,1]) `star_est_ols_age_1' "    &  " "        \\" _newline
file write `hh' "              &  (" %04.3f (est_ols_nocont_se[1,1])                 ")  & ("  %04.3f (est_ols_gender_se[1,1])                  ")  &&  (" %04.3f (est_ols_age_se[1,1])                  ")  &   \\" _newline


file write `hh' "Controlling for Gender & 				& x 		&&		x & 	\\" _newline
file write `hh' "Controlling for Age, and Age Squared & 				&  		&&	x	 & 	\\" _newline
file write `hh' "              & & && &  \\" _newline

file write `hh' "Num of Obs.   &   "        (est_ols_nocont_obs[1,1])                "   &  "        (est_ols_gender_obs[1,1])                 "  &&  "        (est_ols_age_obs[1,1])                 "   &     \\\midrule" _newline

file write `hh' " &&&&& \\" _newline







file write `hh' "\multicolumn{6}{l}{\textbf{Panel B2: Point Estimation with Selection}} \\\midrule" _newline
file write `hh' "                                                             & \multicolumn{2}{c}{PSM regression}                                    && \multicolumn{2}{c}{IPW regression}    \\" _newline
file write `hh' "   \cmidrule{2-3} \cmidrule{5-6}  &         ATT estimates    &     ATE estimates     &&      ATT estimates    &     ATE estimates   \\" _newline
file write `hh' "                                                                   & (1)  &    (2)  && (3)  & (4)  \\\midrule" _newline
file write `hh' "Treatment     &  " %04.3f (psc2_math_be[1,1]) `star_math_12' "   &  " %04.3f (psc3_math_be[1,1]) `star_math_13' "     && " %04.3f (psc4_math_be[1,1]) `star_math_14' "     &  " %04.3f (psc5_math_be[1,1]) `star_math_15' "        \\" _newline
file write `hh' "              &  (" %04.3f (psc2_math_se[1,1])                 ")  & (" %04.3f (psc3_math_se[1,1])                  ")  &&  (" %04.3f (psc4_math_se[1,1])                  ")  & (" %04.3f (psc5_math_se[1,1])                  ")   \\" _newline
file write `hh' "Constant      &       &      &&  " %04.3f (psc4_math_be[2,1]) `star_math_24' "     &  " %04.3f (psc5_math_be[2,1]) `star_math_25' "     \\" _newline
file write `hh' "              &    &   && (" %04.3f (psc4_math_se[2,1])                  ")  & (" %04.3f (psc5_math_se[2,1])                  ")    \\" _newline
file write `hh' "              & & && &  \\" _newline
file write `hh' "Num of Obs.   &   "        (psc2_math_obs[1,1])                "   &  "        (psc3_math_obs[1,1])                 "  &&  "        (psc4_math_obs[1,1])                 "   &  "        (psc5_math_obs[1,1])                 "     \\\midrule" _newline






file write `hh' "\multicolumn{6}{l}{\textbf{Panel B3: Lee's Bounds}} \\\midrule" _newline

file write `hh' "    &        \multicolumn{2}{c}{Lower Bound Estimate}  &&     \multicolumn{2}{c}{Upper Bound Estimate}    \\" _newline
file write `hh' "                                                                   & (1)  &    (2)  && (3)  & (4)  \\\midrule" _newline
file write `hh' "Treatment     &  " %04.3f (est_lee_bounds_nocont_be[1,1]) `star_lee_bounds_nocont_1' "   &  " %04.3f (est_lee_bounds_gender_be[1,1]) `star_lee_bounds_gender_1' "     && " %04.3f (est_lee_bounds_nocont_be[2,1]) `star_lee_bounds_nocont_2' "   &  " %04.3f (est_lee_bounds_gender_be[2,1]) `star_lee_bounds_gender_2' "        \\" _newline
file write `hh' "              &  (" %04.3f (est_lee_bounds_nocont_se[1,1])                 ")  & (" %04.3f (est_lee_bounds_gender_se[1,1])                  ")  &&  (" %04.3f (est_lee_bounds_nocont_se[2,1])                  ")  & (" %04.3f (est_lee_bounds_gender_se[2,1])                  ")   \\" _newline

file write `hh' "Control in Selection Equation (Gender) & 				& x 		&&		 & x	\\" _newline

file write `hh' "              & & && &  \\" _newline

file write `hh' "Num of Selected Obs.\textsuperscript{a}   &   "        (obs_sl_lee_bounds_nocont[1,1])                "   &  "        (obs_sl_lee_bounds_gender[1,1])                 "  &&  "        (obs_sl_lee_bounds_nocont[1,1])                  "   &  "         (obs_sl_lee_bounds_gender[1,1])                 "     \\" _newline

file write `hh' "Num of Total Obs.\textsuperscript{b}   &   "        (obs_lee_bounds_nocont[1,1])                "   &  "        (obs_lee_bounds_gender[1,1])                 "  &&  "        (obs_lee_bounds_nocont[1,1])                  "   &  "         (obs_lee_bounds_gender[1,1])                 "     \\\bottomrule" _newline




file write `hh' "\end{tabular}" _newline
file write `hh' "\end{threeparttable}" _newline
file write `hh' "}" _newline
file write `hh' "\label{tab:addlabelaaa}%" _newline
file write `hh' "\end{table}" _newline







file write `hh' "" _newline
file write `hh' "" _newline
file write `hh' "" _newline
file write `hh' "" _newline

file close `hh'


	
	
	
	

	
restore
	
	
	
	
	
	
preserve
	
keep if grade == 2







forvalues i =1/8 {
	foreach s in be se pv rpv wpv {
		matrix psc`i'_math_`s' = J(7,1,.)
	}
}



foreach s in be se pv rpv wpv {
	matrix est_ols_nocont_`s' = J(7,1,.)
}
foreach s in be se pv rpv wpv {
	matrix est_ols_gender_`s' = J(7,1,.)
}
foreach s in be se pv rpv wpv {
	matrix est_ols_age_`s' = J(7,1,.)
}

foreach s in be se pv rpv wpv {
	matrix est_lee_bounds_nocont_`s' = J(7,1,.)
}

foreach s in be se pv rpv wpv {
	matrix est_lee_bounds_gender_`s' = J(7,1,.)
}




reg dif_psc treatment if ptsbl_overall_score != ., cluster(school_no)


	matrix est_ols_nocont_temp = r(table)
	matrix est_ols_nocont_r2 = e(r2)
	matrix est_ols_nocont_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_ols_nocont_be[`j',1] = est_ols_nocont_temp[1,`j']
		* standard error
		matrix est_ols_nocont_se[`j',1] = est_ols_nocont_temp[2,`j']
		* p value
		matrix est_ols_nocont_pv[`j',1] = est_ols_nocont_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


reg dif_psc treatment student_gender if ptsbl_overall_score != ., cluster(school_no)


	matrix est_ols_gender_temp = r(table)
	matrix est_ols_gender_r2 = e(r2)
	matrix est_ols_gender_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_ols_gender_be[`j',1] = est_ols_gender_temp[1,`j']
		* standard error
		matrix est_ols_gender_se[`j',1] = est_ols_gender_temp[2,`j']
		* p value
		matrix est_ols_gender_pv[`j',1] = est_ols_gender_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


reg dif_psc treatment student_gender age_nonmis age_sq_nonmis dummy_age_missing if ptsbl_overall_score != ., cluster(school_no)


	matrix est_ols_age_temp = r(table)
	matrix est_ols_age_r2 = e(r2)
	matrix est_ols_age_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_ols_age_be[`j',1] = est_ols_age_temp[1,`j']
		* standard error
		matrix est_ols_age_se[`j',1] = est_ols_age_temp[2,`j']
		* p value
		matrix est_ols_age_pv[`j',1] = est_ols_age_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)










teffects psmatch (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis , probit)  if ptsbl_overall_score != .,atet


	matrix psc2_math_temp = r(table)
	matrix psc2_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc2_math_be[`j',1] = psc2_math_temp[1,`j']
		* standard error
		matrix psc2_math_se[`j',1] = psc2_math_temp[2,`j']
		* p value
		matrix psc2_math_pv[`j',1] = psc2_math_temp[4,`j']
	}




teffects psmatch (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit)  if ptsbl_overall_score != .,ate


	matrix psc3_math_temp = r(table)
	matrix psc3_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc3_math_be[`j',1] = psc3_math_temp[1,`j']
		* standard error
		matrix psc3_math_se[`j',1] = psc3_math_temp[2,`j']
		* p value
		matrix psc3_math_pv[`j',1] = psc3_math_temp[4,`j']
	}




teffects ipw (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit) if ptsbl_overall_score != ., atet


	matrix psc4_math_temp = r(table)
	matrix psc4_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc4_math_be[`j',1] = psc4_math_temp[1,`j']
		* standard error
		matrix psc4_math_se[`j',1] = psc4_math_temp[2,`j']
		* p value
		matrix psc4_math_pv[`j',1] = psc4_math_temp[4,`j']
	}


teffects ipw (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit) if ptsbl_overall_score != ., ate


	matrix psc5_math_temp = r(table)
	matrix psc5_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc5_math_be[`j',1] = psc5_math_temp[1,`j']
		* standard error
		matrix psc5_math_se[`j',1] = psc5_math_temp[2,`j']
		* p value
		matrix psc5_math_pv[`j',1] = psc5_math_temp[4,`j']
	}

	
	


	
	
leebounds dif_psc treatment if ptsbl_overall_score != ., vce(bootstrap, reps(4999)) 

mat est_lee_bounds_nocont = r(table)
mat obs_lee_bounds_nocont = e(N)
mat obs_sl_lee_bounds_nocont = e(Nsel)


	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_lee_bounds_nocont_be[`j',1] = est_lee_bounds_nocont[1,`j']
		* standard error
		matrix est_lee_bounds_nocont_se[`j',1] = est_lee_bounds_nocont[2,`j']
		* p value
		matrix est_lee_bounds_nocont_pv[`j',1] = est_lee_bounds_nocont[4,`j']
	}

	

leebounds dif_psc treatment if ptsbl_overall_score != .,  tight(student_gender) vce(bootstrap, reps(4999)) 

mat est_lee_bounds_gender = r(table)
mat obs_lee_bounds_gender = e(N)
mat obs_sl_lee_bounds_gender = e(Nsel)


	
		foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix est_lee_bounds_gender_be[`j',1] = est_lee_bounds_gender[1,`j']
		* standard error
		matrix est_lee_bounds_gender_se[`j',1] = est_lee_bounds_gender[2,`j']
		* p value
		matrix est_lee_bounds_gender_pv[`j',1] = est_lee_bounds_gender[4,`j']
	}

	
	
	
	
	
	
	
	
	
	
	
	

	
	
	

foreach p in math  {
forvalues item = 1/2 {
		forvalues scale = 2/5 {
		if psc`scale'_`p'_pv[`item',1]<=0.01 {
			local star_`p'_`item'`scale' %3s "***"
		}
		else if (psc`scale'_`p'_pv[`item', 1]>0.01) & (psc`scale'_`p'_pv[`item', 1]<=0.05) {
			local star_`p'_`item'`scale' %2s "**"
		}
		else if (psc`scale'_`p'_pv[`item', 1]>0.05) & (psc`scale'_`p'_pv[`item', 1]<=0.10) {
			local star_`p'_`item'`scale' %1s "*"
		}
		else {
			local star_`p'_`item'`scale'  ""
		}
	} // forvalues `scale' loop

}  // forvalues `item' loop
}  // foreach `p' loop





*foreach p in ols_nocont ols_gender ols_age lee_bounds_nocont lee_bounds_gender lee_bounds_nocont5 lee_bounds_gender5 {
foreach p in ols_nocont ols_gender ols_age lee_bounds_nocont lee_bounds_gender {
forvalues item = 1/2 {
*		forvalues scale = 1/6 {
		if est_`p'_pv[`item',1]<=0.01 {
			local star_`p'_`item' %3s "***"
		}
		else if (est_`p'_pv[`item',1]>0.01) & (est_`p'_pv[`item',1]<=0.05) {
			local star_`p'_`item' %2s "**"
		}
		else if (est_`p'_pv[`item',1]>0.05) & (est_`p'_pv[`item',1]<=0.10) {
			local star_`p'_`item' %1s "*"
		}
		else {
			local star_`p'_`item'  ""
		}
*	} // forvalues `scale' loop

}  // forvalues `item' loop
}  // foreach `p' loop






	

tempname hh
file open `hh' using "$pardir/tableH2_panelA.tex", write replace
file write `hh' "" _newline
file write `hh' "% Date: `c(current_date)'" _newline
file write `hh' "% Time: `c(current_time)'" _newline
file write `hh' "" _newline







file write `hh' "\begin{table}[t!]" _newline
file write `hh' "\centering" _newline
file write `hh' "\caption{Long-term Impact of Kumon on Students’ Learning Outcomes: Result of Lee bounds}" _newline
file write `hh' "\label{tab:PSC_math}" _newline
file write `hh' "\scalebox{0.58}{" _newline
file write `hh' "\begin{threeparttable}" _newline
file write `hh' "\begin{tabular}{lccccc}\toprule" _newline 

file write `hh' " &&&&& \\" _newline




file write `hh' "\multicolumn{6}{l}{\textbf{Panel B: PSC Score}} \\\midrule" _newline
file write `hh' " &&&&& \\" _newline
file write `hh' "\multicolumn{6}{l}{\textbf{Panel B1: OLS Results}} \\\midrule" _newline
file write `hh' "Dependent Variable & \multicolumn{5}{c} {First Difference of PSC Math Score and Baseline PTSII-C Score} \\"_newline
file write `hh' "\cmidrule{2-6}"_newline

*file write `hh' "    &        \multicolumn{1}{c}{Lower Bound Estimate}  &    \multicolumn{1}{c}{Upper Bound Estimate}  && &   \\" _newline
file write `hh' "                                                                   & (1)  &    (2)  && (3) &   \\\midrule" _newline
file write `hh' "Treatment     &  " %04.3f (est_ols_nocont_be[1,1]) `star_est_ols_nocont_1' "   &  " %04.3f (est_ols_gender_be[1,1]) `star_est_ols_gender_1' "     &&  " %04.3f (est_ols_age_be[1,1]) `star_est_ols_age_1' "    &  " "        \\" _newline
file write `hh' "              &  (" %04.3f (est_ols_nocont_se[1,1])                 ")  & ("  %04.3f (est_ols_gender_se[1,1])                  ")  &&  (" %04.3f (est_ols_age_se[1,1])                  ")  &   \\" _newline


file write `hh' "Controlling for Gender & 				& x 		&&		x & 	\\" _newline
file write `hh' "Controlling for Age, and Age Squared & 				&  		&&	x	 & 	\\" _newline
file write `hh' "              & & && &  \\" _newline

file write `hh' "Num of Obs.   &   "        (est_ols_nocont_obs[1,1])                "   &  "        (est_ols_gender_obs[1,1])                 "  &&  "        (est_ols_age_obs[1,1])                 "   &     \\\midrule" _newline

file write `hh' " &&&&& \\" _newline







file write `hh' "\multicolumn{6}{l}{\textbf{Panel B2: Point Estimation with Selection}} \\\midrule" _newline
file write `hh' "                                                             & \multicolumn{2}{c}{PSM regression}                                    && \multicolumn{2}{c}{IPW regression}    \\" _newline
file write `hh' "   \cmidrule{2-3} \cmidrule{5-6}  &         ATT estimates    &     ATE estimates     &&      ATT estimates    &     ATE estimates   \\" _newline
file write `hh' "                                                                   & (1)  &    (2)  && (3)  & (4)  \\\midrule" _newline
file write `hh' "Treatment     &  " %04.3f (psc2_math_be[1,1]) `star_math_12' "   &  " %04.3f (psc3_math_be[1,1]) `star_math_13' "     && " %04.3f (psc4_math_be[1,1]) `star_math_14' "     &  " %04.3f (psc5_math_be[1,1]) `star_math_15' "        \\" _newline
file write `hh' "              &  (" %04.3f (psc2_math_se[1,1])                 ")  & (" %04.3f (psc3_math_se[1,1])                  ")  &&  (" %04.3f (psc4_math_se[1,1])                  ")  & (" %04.3f (psc5_math_se[1,1])                  ")   \\" _newline
file write `hh' "Constant      &       &      &&  " %04.3f (psc4_math_be[2,1]) `star_math_24' "     &  " %04.3f (psc5_math_be[2,1]) `star_math_25' "     \\" _newline
file write `hh' "              &    &   && (" %04.3f (psc4_math_se[2,1])                  ")  & (" %04.3f (psc5_math_se[2,1])                  ")    \\" _newline
file write `hh' "              & & && &  \\" _newline
file write `hh' "Num of Obs.   &   "        (psc2_math_obs[1,1])                "   &  "        (psc3_math_obs[1,1])                 "  &&  "        (psc4_math_obs[1,1])                 "   &  "        (psc5_math_obs[1,1])                 "     \\\midrule" _newline






file write `hh' "\multicolumn{6}{l}{\textbf{Panel B3: Lee's Bounds}} \\\midrule" _newline

file write `hh' "    &        \multicolumn{2}{c}{Lower Bound Estimate}  &&     \multicolumn{2}{c}{Upper Bound Estimate}    \\" _newline
file write `hh' "                                                                   & (1)  &    (2)  && (3)  & (4)  \\\midrule" _newline
file write `hh' "Treatment     &  " %04.3f (est_lee_bounds_nocont_be[1,1]) `star_lee_bounds_nocont_1' "   &  " %04.3f (est_lee_bounds_gender_be[1,1]) `star_lee_bounds_gender_1' "     && " %04.3f (est_lee_bounds_nocont_be[2,1]) `star_lee_bounds_nocont_2' "   &  " %04.3f (est_lee_bounds_gender_be[2,1]) `star_lee_bounds_gender_2' "        \\" _newline
file write `hh' "              &  (" %04.3f (est_lee_bounds_nocont_se[1,1])                 ")  & (" %04.3f (est_lee_bounds_gender_se[1,1])                  ")  &&  (" %04.3f (est_lee_bounds_nocont_se[2,1])                  ")  & (" %04.3f (est_lee_bounds_gender_se[2,1])                  ")   \\" _newline

file write `hh' "Control in Selection Equation (Gender) & 				& x 		&&		 & x	\\" _newline

file write `hh' "              & & && &  \\" _newline

file write `hh' "Num of Selected Obs.\textsuperscript{a}   &   "        (obs_sl_lee_bounds_nocont[1,1])                "   &  "        (obs_sl_lee_bounds_gender[1,1])                 "  &&  "        (obs_sl_lee_bounds_nocont[1,1])                  "   &  "         (obs_sl_lee_bounds_gender[1,1])                 "     \\" _newline

file write `hh' "Num of Total Obs.\textsuperscript{b}   &   "        (obs_lee_bounds_nocont[1,1])                "   &  "        (obs_lee_bounds_gender[1,1])                 "  &&  "        (obs_lee_bounds_nocont[1,1])                  "   &  "         (obs_lee_bounds_gender[1,1])                 "     \\\bottomrule" _newline




file write `hh' "\end{tabular}" _newline
file write `hh' "\end{threeparttable}" _newline
file write `hh' "}" _newline
file write `hh' "\label{tab:addlabelaaa}%" _newline
file write `hh' "\end{table}" _newline







file write `hh' "" _newline
file write `hh' "" _newline
file write `hh' "" _newline
file write `hh' "" _newline

file close `hh'


	
	
	
	

	
restore
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/*
	
	
	

preserve

keep if grade == 4




forvalues i =1/8 {
	foreach s in be se pv rpv wpv {
		matrix psc`i'_math_`s' = J(7,1,.)
	}
}




reg dif_psc treatment if ptsbl_overall_score != ., cluster(school_no)


	matrix psc1_math_temp = r(table)
	matrix psc1_math_r2 = e(r2)
	matrix psc1_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc1_math_be[`j',1] = psc1_math_temp[1,`j']
		* standard error
		matrix psc1_math_se[`j',1] = psc1_math_temp[2,`j']
		* p value
		matrix psc1_math_pv[`j',1] = psc1_math_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


reg dif_psc treatment student_gender if ptsbl_overall_score != ., cluster(school_no)


	matrix psc1_math_temp = r(table)
	matrix psc1_math_r2 = e(r2)
	matrix psc1_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc1_math_be[`j',1] = psc1_math_temp[1,`j']
		* standard error
		matrix psc1_math_se[`j',1] = psc1_math_temp[2,`j']
		* p value
		matrix psc1_math_pv[`j',1] = psc1_math_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


reg dif_psc treatment student_gender age_nonmis age_sq_nonmis dummy_age_missing if ptsbl_overall_score != ., cluster(school_no)


	matrix psc1_math_temp = r(table)
	matrix psc1_math_r2 = e(r2)
	matrix psc1_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc1_math_be[`j',1] = psc1_math_temp[1,`j']
		* standard error
		matrix psc1_math_se[`j',1] = psc1_math_temp[2,`j']
		* p value
		matrix psc1_math_pv[`j',1] = psc1_math_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)










teffects psmatch (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis , probit)  if ptsbl_overall_score != .,atet


	matrix psc2_math_temp = r(table)
	matrix psc2_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc2_math_be[`j',1] = psc2_math_temp[1,`j']
		* standard error
		matrix psc2_math_se[`j',1] = psc2_math_temp[2,`j']
		* p value
		matrix psc2_math_pv[`j',1] = psc2_math_temp[4,`j']
	}




teffects psmatch (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit)  if ptsbl_overall_score != .,ate


	matrix psc3_math_temp = r(table)
	matrix psc3_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc3_math_be[`j',1] = psc3_math_temp[1,`j']
		* standard error
		matrix psc3_math_se[`j',1] = psc3_math_temp[2,`j']
		* p value
		matrix psc3_math_pv[`j',1] = psc3_math_temp[4,`j']
	}




teffects ipw (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit) if ptsbl_overall_score != ., atet


	matrix psc4_math_temp = r(table)
	matrix psc4_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc4_math_be[`j',1] = psc4_math_temp[1,`j']
		* standard error
		matrix psc4_math_se[`j',1] = psc4_math_temp[2,`j']
		* p value
		matrix psc4_math_pv[`j',1] = psc4_math_temp[4,`j']
	}


teffects ipw (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit) if ptsbl_overall_score != ., ate


	matrix psc5_math_temp = r(table)
	matrix psc5_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc5_math_be[`j',1] = psc5_math_temp[1,`j']
		* standard error
		matrix psc5_math_se[`j',1] = psc5_math_temp[2,`j']
		* p value
		matrix psc5_math_pv[`j',1] = psc5_math_temp[4,`j']
	}

	
	


	
	
leebounds dif_psc treatment if ptsbl_overall_score != ., vce(bootstrap, reps(999)) 

mat est_lee_bounds_nocont = r(table)
mat obs_lee_bounds_nocont = e(N)
mat obs_sl_lee_bounds_nocont = e(Nsel)




leebounds dif_psc treatment if ptsbl_overall_score != .,  tight(student_gender) vce(bootstrap, reps(999)) 

mat est_lee_bounds_gender = r(table)
mat obs_lee_bounds_gender = e(N)
mat obs_sl_lee_bounds_gender = e(Nsel)



restore













preserve

keep if grade == 2


forvalues i =1/8 {
	foreach s in be se pv rpv wpv {
		matrix psc`i'_math_`s' = J(7,1,.)
	}
}




reg dif_psc treatment if ptsbl_overall_score != ., cluster(school_no)


	matrix psc1_math_temp = r(table)
	matrix psc1_math_r2 = e(r2)
	matrix psc1_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc1_math_be[`j',1] = psc1_math_temp[1,`j']
		* standard error
		matrix psc1_math_se[`j',1] = psc1_math_temp[2,`j']
		* p value
		matrix psc1_math_pv[`j',1] = psc1_math_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


reg dif_psc treatment student_gender if ptsbl_overall_score != ., cluster(school_no)


	matrix psc1_math_temp = r(table)
	matrix psc1_math_r2 = e(r2)
	matrix psc1_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc1_math_be[`j',1] = psc1_math_temp[1,`j']
		* standard error
		matrix psc1_math_se[`j',1] = psc1_math_temp[2,`j']
		* p value
		matrix psc1_math_pv[`j',1] = psc1_math_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


reg dif_psc treatment student_gender age_nonmis age_sq_nonmis dummy_age_missing if ptsbl_overall_score != ., cluster(school_no)


	matrix psc1_math_temp = r(table)
	matrix psc1_math_r2 = e(r2)
	matrix psc1_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc1_math_be[`j',1] = psc1_math_temp[1,`j']
		* standard error
		matrix psc1_math_se[`j',1] = psc1_math_temp[2,`j']
		* p value
		matrix psc1_math_pv[`j',1] = psc1_math_temp[4,`j']
	}

*	cgmwildboot `i' treatment wrongDT, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)










teffects psmatch (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis , probit)  if ptsbl_overall_score != .,atet


	matrix psc2_math_temp = r(table)
	matrix psc2_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc2_math_be[`j',1] = psc2_math_temp[1,`j']
		* standard error
		matrix psc2_math_se[`j',1] = psc2_math_temp[2,`j']
		* p value
		matrix psc2_math_pv[`j',1] = psc2_math_temp[4,`j']
	}




teffects psmatch (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit)  if ptsbl_overall_score != .,ate


	matrix psc3_math_temp = r(table)
	matrix psc3_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc3_math_be[`j',1] = psc3_math_temp[1,`j']
		* standard error
		matrix psc3_math_se[`j',1] = psc3_math_temp[2,`j']
		* p value
		matrix psc3_math_pv[`j',1] = psc3_math_temp[4,`j']
	}




teffects ipw (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit) if ptsbl_overall_score != ., atet


	matrix psc4_math_temp = r(table)
	matrix psc4_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc4_math_be[`j',1] = psc4_math_temp[1,`j']
		* standard error
		matrix psc4_math_se[`j',1] = psc4_math_temp[2,`j']
		* p value
		matrix psc4_math_pv[`j',1] = psc4_math_temp[4,`j']
	}


teffects ipw (dif_psc) (treatment student_gender age_nonmis age_sq_nonmis, probit) if ptsbl_overall_score != ., ate


	matrix psc5_math_temp = r(table)
	matrix psc5_math_obs = e(N)

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix psc5_math_be[`j',1] = psc5_math_temp[1,`j']
		* standard error
		matrix psc5_math_se[`j',1] = psc5_math_temp[2,`j']
		* p value
		matrix psc5_math_pv[`j',1] = psc5_math_temp[4,`j']
	}

	
	


	
	
leebounds dif_psc treatment if ptsbl_overall_score != ., vce(bootstrap, reps(999)) 

mat est_lee_bounds_nocont = r(table)
mat obs_lee_bounds_nocont = e(N)
mat obs_sl_lee_bounds_nocont = e(Nsel)




leebounds dif_psc treatment if ptsbl_overall_score != .,  tight(student_gender) vce(bootstrap, reps(999)) 

mat est_lee_bounds_gender = r(table)
mat obs_lee_bounds_gender = e(N)
mat obs_sl_lee_bounds_gender = e(Nsel)





restore
	


	
	
	
	
	
	
	
	
	
	
	


